package com.zb.zeus.system.api.factory;

import com.zb.zeus.common.core.domain.R;
import com.zb.zeus.system.api.RemoteAuthService;
import com.zb.zeus.system.api.model.LoginForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 用户服务降级处理
 *
 * @author zb.zeus
 */
@Component
public class RemoteAuthFallbackFactory implements FallbackFactory<RemoteAuthService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteAuthFallbackFactory.class);

    @Override
    public RemoteAuthService create(Throwable throwable) {
        log.error("授权授权服务调用失败:", throwable);
        return new RemoteAuthService() {

            @Override
            public R<Map<String, Object>> login(LoginForm loginForm) {
                return R.fail("授权服务不可用, 登入失败请稍后重试");
            }

            @Override
            public R<Map<String, Object>> logout() {
                return R.fail("授权服务不可用, 登出失败请稍后重试");
            }

            @Override
            public R<?> refresh() {
                return R.fail("授权服务不可用, 刷新失败请稍后重试");
            }
        };
    }
}
